<!--
 * @Author: 胡俊/treence
 * @Date: 2022-05-13 15:55:19
 * @LastEditors: 徐伟杰
 * @LastEditTime: 2022-11-04 15:08:04
 * @Description: 
 * @Email: treence@gmail.com
 * @Company: 3xData
 * @youWant: add you want
-->
<template>
  <view class="people_page">
    <!-- 顶部自定义导航栏 -->
    <action-bar :options="navOptions" />
    <view class="listContainer" v-if="list.length > 0">
      <scroll-view-y @refresh="refresh()" @getMore="getMore()" :pageNo="searchObject.pageNo"
        :pageSize="searchObject.pageSize" :total="total" :height="230">
        <template slot="scrollView_content">
          <!--列表-->
          <view class="bar" v-for="(item, i) in list" :key="i" @click="toInfo(item)">
            <view class="left">
              <image mode="widthFix" class="icon" :src="baseImgUrl + '/myZone/decorate_titleArrow.png'" />
              <view class="names">{{ item.name }}</view>
              <view class="post">人员类别：{{ getPersonType(item) }}</view>
              <view class="post">技术负责人：{{ item.isResponsible ? item.isResponsible : '否' }}</view>
            </view>
          </view>
        </template>
      </scroll-view-y>
    </view>
    <no-data v-else text="暂无消息通知"></no-data>
    <!-- 底部新增 -->
    <view class="footer">
      <view class="btn_add" @click="toInfo()">
        <view class="cuIcon-add" />
        新增人员
      </view>
    </view>
  </view>
</template>
<script>
import { baseImgUrl } from "@/config.js";
import ScrollViewY from "@/components/scrollViewY/index.vue";
export default {
  components: {
    ScrollViewY,
  },
  data() {
    return {
      baseImgUrl: baseImgUrl,
      list: [],
      navOptions: {
        // 导航栏配置参数
        statusBar: "dark",
        left: {
          icon: "back",
        },
        center: {
          title: "单位人员",
        },
      },
      total: 0,
      // 列表数据
      searchObject: {
        // 搜索条件
        pageNo: 1,
        pageSize: 10,
      },
      dataStatus: "刷新", // 用于解决闪烁问题
    };
  },
  //! 提供给组件 下拉刷新上拉加载的 数据获取的方法
  provide() {
    return {
      getData: this.getList,
    };
  },
  onShow() {
    this.getList();
  },
  methods: {
    // 获取人员类型
    getPersonType(row) {
      if (row.registeredFireEngineer) {
        return "注册消防工程师";
      } else {
        return "消防设施操作人员";
      }
    },

    // 跳转至表单
    toInfo(item) {
      if (item) {
        uni.navigateTo({
          url: "../../pages_workTableChild/peopleManage/form?id=" + item.staffId + "&type=edit",
          success: () => { },
        });
      } else {
        uni.navigateTo({
          url: "../../pages_workTableChild/peopleManage/form?type=add",
          success: () => { },
        });
      }
    },

    // 获取列表
    getList() {
      return new Promise((resolve, reject) => {
        this.$store
          .dispatch("peopleManage_list", this.searchObject)
          .then((res) => {
            if (res && res.code === 200) {
              this.total = res.data.total;
              this.dataStatus === "刷新"
                ? (this.list = res.data.items)
                : this.list.push(...res.data.items);
              resolve(res.data);
            }
          });
      });
    },

    // 刷新数据
    refresh() {
      this.dataStatus = "刷新";
      this.searchObject.pageNo = 1;
    },
    // 上拉加载
    getMore() {
      if (this.searchObject.pageNo * this.searchObject.pageSize <= this.total) {
        this.dataStatus = "加载更多";
        this.searchObject.pageNo++;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.people_page {
  height: 100vh;
  width: 100vw;
  background: $OVERALL_SITUATION_BACKGROUND_GRADIENT;
}

.listContainer {
  width: calc(100% - 40rpx);
  margin: 0 auto;
  height: calc(100% - 150rpx);
}

.bar {
  display: flex;
  align-items: center;
  position: relative;
  border-radius: 20rpx;
  padding: 24rpx;
  margin-bottom: 20rpx;
  background-color: white;

  &:active {
    background-color: #f8f8f8;
  }

  &:last-child {
    margin-bottom: 150rpx;
  }
}

.left {
  width: 100vw;
  position: relative;
  border-bottom: 1rpx solid #dddddd;
}

.names {
  font-weight: bold;
  font-size: 36rpx;
}

.post {
  margin-top: 20rpx;
  color: #999;
  font-size: 26rpx;

  &:last-child {
    padding-bottom: 20rpx;
  }
}

.icon {
  position: absolute;
  top: 78rpx;
  margin-left: 650rpx;
  width: 20rpx;
}

.footer {
  position: fixed;
  width: 100%;
  background: white;
  bottom: 0px;
  padding: 24rpx 24rpx 40rpx 24rpx;
  border-radius: 20rpx 20rpx 0 0;
  box-shadow: 0 -10rpx 10rpx 0 rgba(0, 0, 0, 0.2);

  .btn_add {
    background: $OVERALL_CONFIRM_BUTTON_COLOR;
    border-radius: 20rpx;
    text-align: center;
    color: white;
    font-size: 36rpx;
    line-height: 80rpx;

    .cuIcon-add {
      display: inline-block;
    }
  }
}

::v-deep .uni-scroll-view {
  overflow: none;
}
</style>
